/**
 * Description: CardDAOImpl.java
 * Copyright (c) 2008-2009  Neo. 
 * All Rights Reserved.
 * @version 1.0  2010-01-13 created
 */
package org.paradise.dms.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.SQLQuery;
import org.paradise.dms.pojo.Card;
import org.springframework.stereotype.Service;

import com.dheaven.framework.dao.BaseHibernateDao;
import com.dheaven.framework.dao.DaoException;

/**
 * Description: Copyright (c) 2008-2009 Neo. All Rights Reserved.
 * 
 * @version 1.0 2010-01-13 created
 */
@Service
public class CardDAOImpl extends BaseHibernateDao<Card> {
	private static Logger log = Logger.getLogger(CardDAOImpl.class);


	

	

	/**
	 * 
	 * Description: 通过饭卡的id取得学生学号
	 * 
	 * @Version1.0 
	 * @param carid
	 *            
	 * @return
	 * @throws DaoException
	 */
	public Card getStudentNo(String cardid) {
		try {
			return (Card) this.find(
					"from Card where cardid = ? ",
					new Object[] { cardid }).get(0);
		} catch (DaoException e) {
			log.error("DMS_error:通过饭卡的id取得学生学号");
			log.error("错误原因:" + e);
		}
		return null;
	}

	/**
	 * 
	 * Description: 通过饭卡的id取得学生信息
	 * 
	 * @Version1.0 
	 * @param cardid
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List findStudentByCardid(
			String cardid) {
		try {
			SQLQuery query = (SQLQuery) this
			.getSession()
			.createSQLQuery(
					"select  Student.studentno,Student.studentname from Student left join Card on Card.idserial = Student.studentno where " +
					"Card.cardid =  " +cardid);

			return query.list();
		} catch (Exception e) {
			log.error("DMS_error:通过饭卡的id取得学生学号");
			log.error("错误原因:" + e);
		}
		return null;
		
	}
	
}